<!DOCTYPE html>


<html theme="dark" showBanner="true" hasBanner="false" > 
<link href="https://cdn.staticfile.org/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet">
<link href="https://cdn.staticfile.org/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet">
<link href="https://cdn.staticfile.org/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet">
<script src="/hexo-blog/js/color.global.min.js" ></script>
<script src="/hexo-blog/js/load-settings.js" ></script>
<head>
  <meta charset="utf-8">
  
  
  

  
  <title>CSS函数大全（四）：杂项和未来 | bressanone</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="preload" href="/hexo-blog/css/fonts/Roboto-Regular.ttf" as="font" type="font/ttf" crossorigin="anonymous">
  <link rel="preload" href="/hexo-blog/css/fonts/Roboto-Bold.ttf" as="font" type="font/ttf" crossorigin="anonymous">

  <meta name="description" content="这是我参与11月更文挑战的第27天，活动详情查看：2021最后一次更文挑战 本系列目标是做一个css函数完全指南，将尽可能罗列css中所有的函数及其用法，当需要使用或者理解某个css函数的时候，只要来这里寻找就可以了。 杂项url最常用的函数之一，表示一个文件地址。可以是相对路径、绝对路径或base64，或者一个svg的id 这个函数可用于background, background-image,">
<meta property="og:type" content="article">
<meta property="og:title" content="CSS函数大全（四）：杂项和未来">
<meta property="og:url" content="http://example.com/2021/11/27/CSS%E5%87%BD%E6%95%B0%E5%A4%A7%E5%85%A8%EF%BC%88%E5%9B%9B%EF%BC%89%EF%BC%9A%E6%9D%82%E9%A1%B9%E5%92%8C%E6%9C%AA%E6%9D%A5/index.html">
<meta property="og:site_name" content="bressanone">
<meta property="og:description" content="这是我参与11月更文挑战的第27天，活动详情查看：2021最后一次更文挑战 本系列目标是做一个css函数完全指南，将尽可能罗列css中所有的函数及其用法，当需要使用或者理解某个css函数的时候，只要来这里寻找就可以了。 杂项url最常用的函数之一，表示一个文件地址。可以是相对路径、绝对路径或base64，或者一个svg的id 这个函数可用于background, background-image,">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/5a4ba5ff4494443f8dd7ec51077522b7.png">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/754b8961911e4a0e8aae1b9b7a77b4bd.png">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/cf06032c734549a09510f6424aaa5b81.png">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/2bb45eb7f59d40f381a2ad904fa739ea.png">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/6d8aa40eee8a404c894642e4c613d7ff.png">
<meta property="og:image" content="http://example.com/2021/11/27/imgs/62e213d1a84048648ebc55b40cef1913.png">
<meta property="article:published_time" content="2021-11-26T16:00:00.000Z">
<meta property="article:modified_time" content="2024-04-13T12:20:29.580Z">
<meta property="article:author" content="Zachary">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="CSS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/2021/11/27/imgs/5a4ba5ff4494443f8dd7ec51077522b7.png">
  
  
    <link rel="icon" media="(prefers-color-scheme: light)" href="/hexo-blog/images/favicon-light-32.png" sizes="32x32">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/hexo-blog/images/favicon-light-128.png" sizes="128x128">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/hexo-blog/images/favicon-light-180.png" sizes="180x180">
    <link rel="icon" media="(prefers-color-scheme: light)" href="/hexo-blog/images/favicon-light-192.png" sizes="192x192">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/hexo-blog/images/favicon-dark-32.png" sizes="32x32">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/hexo-blog/images/favicon-dark-128.png" sizes="128x128">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/hexo-blog/images/favicon-dark-180.png" sizes="180x180">
    <link rel="icon" media="(prefers-color-scheme: dark)" href="/hexo-blog/images/favicon-dark-192.png" sizes="192x192">
  
  
<link rel="stylesheet" href="/hexo-blog/css/style.css">

<meta name="generator" content="Hexo 7.1.1"></head>

<body>
  
   
  <div id="main-grid" class="  ">
    <div id="nav" class=""  >
      <navbar id="navbar">
  <nav id="title-nav">
    <a href="/hexo-blog/">
      <div id="vivia-logo">
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
        <div class="dot"></div>
      </div>
      <div>bressanone </div>
    </a>
  </nav>
  <nav id="main-nav">
    
      <a class="main-nav-link" href="/hexo-blog/">主页</a>
    
      <a class="main-nav-link" href="/hexo-blog/archives">归档</a>
    
      <a class="main-nav-link" href="/hexo-blog/about">关于</a>
    
  </nav>
  <nav id="sub-nav">
    <a id="theme-btn" class="nav-icon">
      <span class="light-mode-icon"><svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M438.5-829.913v-48q0-17.452 11.963-29.476 11.964-12.024 29.326-12.024 17.363 0 29.537 12.024t12.174 29.476v48q0 17.452-11.963 29.476-11.964 12.024-29.326 12.024-17.363 0-29.537-12.024T438.5-829.913Zm0 747.826v-48q0-17.452 11.963-29.476 11.964-12.024 29.326-12.024 17.363 0 29.537 12.024t12.174 29.476v48q0 17.452-11.963 29.476-11.964 12.024-29.326 12.024-17.363 0-29.537-12.024T438.5-82.087ZM877.913-438.5h-48q-17.452 0-29.476-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537t29.476-12.174h48q17.452 0 29.476 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T877.913-438.5Zm-747.826 0h-48q-17.452 0-29.476-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537T82.087-521.5h48q17.452 0 29.476 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T130.087-438.5Zm660.174-290.87-34.239 32q-12.913 12.674-29.565 12.174-16.653-.5-29.327-13.174-12.674-12.673-12.554-28.826.12-16.152 12.794-28.826l33-35q12.913-12.674 30.454-12.674t30.163 12.847q12.709 12.846 12.328 30.826-.38 17.98-13.054 30.653ZM262.63-203.978l-32 34q-12.913 12.674-30.454 12.674t-30.163-12.847q-12.709-12.846-12.328-30.826.38-17.98 13.054-30.653l33.239-31q12.913-12.674 29.565-12.174 16.653.5 29.327 13.174 12.674 12.673 12.554 28.826-.12 16.152-12.794 28.826Zm466.74 33.239-32-33.239q-12.674-12.913-12.174-29.565.5-16.653 13.174-29.327 12.673-12.674 28.826-13.054 16.152-.38 28.826 12.294l35 33q12.674 12.913 12.674 30.454t-12.847 30.163q-12.846 12.709-30.826 12.328-17.98-.38-30.653-13.054ZM203.978-697.37l-34-33q-12.674-12.913-13.174-29.945-.5-17.033 12.174-29.707t31.326-13.293q18.653-.62 31.326 13.054l32 34.239q11.674 12.913 11.174 29.565-.5 16.653-13.174 29.327-12.673 12.674-28.826 12.554-16.152-.12-28.826-12.794ZM480-240q-100 0-170-70t-70-170q0-100 70-170t170-70q100 0 170 70t70 170q0 100-70 170t-170 70Zm-.247-82q65.703 0 111.475-46.272Q637-414.544 637-480.247t-45.525-111.228Q545.95-637 480.247-637t-111.475 45.525Q323-545.95 323-480.247t45.525 111.975Q414.05-322 479.753-322ZM481-481Z"/></svg></span>
      <span class="dark-mode-icon"><svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M480.239-116.413q-152.63 0-258.228-105.478Q116.413-327.37 116.413-480q0-130.935 77.739-227.435t206.304-125.043q43.022-9.631 63.87 10.869t3.478 62.805q-8.891 22.043-14.315 44.463-5.424 22.42-5.424 46.689 0 91.694 64.326 155.879 64.325 64.186 156.218 64.186 24.369 0 46.978-4.946 22.609-4.945 44.413-14.076 42.826-17.369 62.967 1.142 20.142 18.511 10.511 61.054Q807.174-280 712.63-198.206q-94.543 81.793-232.391 81.793Zm0-95q79.783 0 143.337-40.217 63.554-40.218 95.793-108.283-15.608 4.044-31.097 5.326-15.49 1.283-31.859.805-123.706-4.066-210.777-90.539-87.071-86.473-91.614-212.092-.24-16.369.923-31.978 1.164-15.609 5.446-30.978-67.826 32.478-108.282 96.152Q211.652-559.543 211.652-480q0 111.929 78.329 190.258 78.329 78.329 190.258 78.329ZM466.13-465.891Z"/></svg></span>
    </a>
    
    <div id="nav-menu-btn" class="nav-icon">
      <svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M177.37-252.282q-17.453 0-29.477-11.964-12.024-11.963-12.024-29.326t12.024-29.537q12.024-12.174 29.477-12.174h605.26q17.453 0 29.477 11.964 12.024 11.963 12.024 29.326t-12.024 29.537q-12.024 12.174-29.477 12.174H177.37Zm0-186.218q-17.453 0-29.477-11.963-12.024-11.964-12.024-29.326 0-17.363 12.024-29.537T177.37-521.5h605.26q17.453 0 29.477 11.963 12.024 11.964 12.024 29.326 0 17.363-12.024 29.537T782.63-438.5H177.37Zm0-186.217q-17.453 0-29.477-11.964-12.024-11.963-12.024-29.326t12.024-29.537q12.024-12.174 29.477-12.174h605.26q17.453 0 29.477 11.964 12.024 11.963 12.024 29.326t-12.024 29.537q-12.024 12.174-29.477 12.174H177.37Z"/></svg>
    </div>
  </nav>
</navbar>
<div id="nav-dropdown" class="hidden">
  <div id="dropdown-link-list">
    
      <a class="nav-dropdown-link" href="/hexo-blog/">主页</a>
    
      <a class="nav-dropdown-link" href="/hexo-blog/archives">归档</a>
    
      <a class="nav-dropdown-link" href="/hexo-blog/about">关于</a>
    
     
    </div>
</div>
<script>
  let dropdownBtn = document.getElementById("nav-menu-btn");
  let dropdownEle = document.getElementById("nav-dropdown");
  dropdownBtn.onclick = function() {
    dropdownEle.classList.toggle("hidden");
  }
</script>
    </div>
    <div id="sidebar-wrapper">
      <sidebar id="sidebar">
  
    <div class="widget-wrap">
  <div class="info-card">
    <div class="avatar">
      
      <div class="img-dim"></div>
    </div>
    <div class="info">
      <div class="username">Zachary </div>
      <div class="dot"></div>
      <div class="subtitle"> </div>
      <div class="link-list">
        
          <a class="link-btn" target="_blank" rel="noopener" href="https://github.com/zzy1661" title="GitHub"><i class="fa-brands fa-github"></i></a>
         
      </div>  
    </div>
  </div>
</div>

  
  <div class="sticky">
    
      


  <div class="widget-wrap">
    <div class="widget">
      <h3 class="widget-title">分类</h3>
      <div class="category-box">
            <a class="category-link" href="/hexo-blog/categories/%E5%89%8D%E7%AB%AF%E7%AC%94%E8%AE%B0/">
                前端笔记
                <div class="category-count">78</div>
            </a>
        
            <a class="category-link" href="/hexo-blog/categories/%E7%AE%97%E6%B3%95%E6%89%8B%E5%86%8C/">
                算法手册
                <div class="category-count">7</div>
            </a>
        </div>
    </div>
  </div>


    
      
  <div class="widget-wrap">
    <div class="widget">
      <h3 class="widget-title">标签</h3>
      <ul class="widget-tag-list" itemprop="keywords"><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Ant-Design/" rel="tag">Ant Design</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/CSS/" rel="tag">CSS</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Canvas/" rel="tag">Canvas</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Docker/" rel="tag">Docker</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/ECMAScript-6/" rel="tag">ECMAScript 6</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/JavaScript/" rel="tag">JavaScript</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Less/" rel="tag">Less</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/MobX/" rel="tag">MobX</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/MongoDB/" rel="tag">MongoDB</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/NPM/" rel="tag">NPM</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/NestJS/" rel="tag">NestJS</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Node-js/" rel="tag">Node.js</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Postman/" rel="tag">Postman</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/React-js/" rel="tag">React.js</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Redux/" rel="tag">Redux</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/TypeScript/" rel="tag">TypeScript</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/UML/" rel="tag">UML</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Webpack/" rel="tag">Webpack</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/Yeoman/" rel="tag">Yeoman</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E5%89%8D%E7%AB%AF/" rel="tag">前端</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E6%9E%B6%E6%9E%84/" rel="tag">架构</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" rel="tag">正则表达式</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E7%88%AC%E8%99%AB/" rel="tag">爬虫</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E7%AE%97%E6%B3%95/" rel="tag">算法</a></li><li class="widget-tag-list-item"><a class="widget-tag-list-link" href="/hexo-blog/tags/%E9%9D%A2%E8%AF%95/" rel="tag">面试</a></li></ul>
    </div>
  </div>


    
  </div>
</sidebar>
    </div>
    <div id="content-body">
       


<article id="post-CSS函数大全（四）：杂项和未来" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  
    
   
  <div class="article-inner">
    <div class="article-main">
      <header class="article-header">
        
<div class="main-title-bar">
  <div class="main-title-dot"></div>
  
    
      <h1 class="p-name article-title" itemprop="headline name">
        CSS函数大全（四）：杂项和未来
      </h1>
    
  
</div>

        <div class='meta-info-bar'>
          <div class="meta-info">
  <time class="dt-published" datetime="2021-11-26T16:00:00.000Z" itemprop="datePublished">2021-11-27</time>
</div>
          <div class="need-seperator meta-info">
            <div class="meta-cate-flex">
  
  <a class="meta-cate-link" href="/hexo-blog/categories/%E5%89%8D%E7%AB%AF%E7%AC%94%E8%AE%B0/">前端笔记</a>
   
</div>
  
          </div>
          <div class="wordcount need-seperator meta-info">
            5.3k 词 
          </div>
        </div>
        
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/hexo-blog/tags/CSS/" rel="tag">CSS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/hexo-blog/tags/%E5%89%8D%E7%AB%AF/" rel="tag">前端</a></li></ul>

      </header>
      <div class="e-content article-entry" itemprop="articleBody">
        
          <p>这是我参与11月更文挑战的第27天，活动详情查看：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7023643374569816095" title="https://juejin.cn/post/7023643374569816095">2021最后一次更文挑战</a></p>
<p>本系列目标是做一个css函数完全指南，将尽可能罗列css中所有的函数及其用法，当需要使用或者理解某个css函数的时候，只要来这里寻找就可以了。</p>
<h2 id="杂项"><a href="#杂项" class="headerlink" title="杂项"></a>杂项</h2><h3 id="url"><a href="#url" class="headerlink" title="url"></a>url</h3><p>最常用的函数之一，表示一个文件地址。可以是相对路径、绝对路径或base64，或者一个svg的id</p>
<p>这个函数可用于<code>background</code>, <code>background-image</code>, <code>border</code>, <code>border-image</code>, <code>border-image-source</code>, <code>content</code>, <code>cursor</code>, <code>filter</code>, <code>list-style</code>, <code>list-style-image</code>, <code>mask</code>, <code>mask-image</code>, <code>offset-path</code>,@counter-style&#x2F;symbol和@font-face中的<code>src</code></p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">offset-path: <span class="built_in">url</span>(<span class="string">#path</span>);</span><br><span class="line"><span class="attribute">mask-image</span>: <span class="built_in">url</span>(<span class="string">&quot;masks.svg#mask1&quot;</span>);</span><br><span class="line"><span class="attribute">cursor</span>: <span class="built_in">url</span>(<span class="string">pointer.cur</span>), pointer;</span><br></pre></td></tr></table></figure>

<h3 id="attr"><a href="#attr" class="headerlink" title="attr"></a>attr</h3><p>用来获取选择到的元素的某一HTML属性值。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span><br><span class="line"><span class="language-css">    <span class="selector-tag">div</span><span class="selector-pseudo">::after</span> &#123;</span></span><br><span class="line"><span class="language-css">        <span class="attribute">content</span>: <span class="string">&quot;----&quot;</span> <span class="built_in">attr</span>(data-extra)</span></span><br><span class="line"><span class="language-css">    &#125;</span></span><br><span class="line"><span class="language-css"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">data-extra</span>=<span class="string">&quot;lalalla&quot;</span>&gt;</span>test<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/5a4ba5ff4494443f8dd7ec51077522b7.png" alt="image.png"></p>
<p>注意：</p>
<ul>
<li><code>attr()</code> 理论上能用于所有的CSS属性，但目前支持的仅有伪元素的 <a href="https://developer.mozilla.org%2Fzh-CN%2Fdocs%2FWeb%2FCSS%2Fcontent" title="https://developer.mozilla.org/zh-CN/docs/Web/CSS/content"><code>content</code></a> 属性</li>
<li>它的高级语法<code>attr( attribute-name &lt;type-or-unit&gt;? [, &lt;fallback&gt; ]? )</code>,目前也没有浏览器支持。</li>
</ul>
<h3 id="var"><a href="#var" class="headerlink" title="var"></a>var</h3><p>css变量变量</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"> <span class="selector-pseudo">:root</span> &#123;</span><br><span class="line">    <span class="attr">--size</span>:<span class="number">100px</span>;</span><br><span class="line">    <span class="attr">--color</span>: antiquewhite;</span><br><span class="line">    <span class="attr">--bg</span>: tomato;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-id">#container</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="built_in">var</span>(--size);</span><br><span class="line">    <span class="attribute">height</span>: <span class="built_in">var</span>(--size);</span><br><span class="line">    <span class="attribute">color</span>: <span class="built_in">var</span>(--color);</span><br><span class="line">    <span class="attribute">background-color</span>:<span class="built_in">var</span>(--bg) ;</span><br><span class="line">&#125;</span><br><span class="line">&lt;<span class="selector-tag">div</span> id=&quot;container&quot;&gt;text&lt;/<span class="selector-tag">div</span>&gt;</span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/754b8961911e4a0e8aae1b9b7a77b4bd.png" alt="image.png"></p>
<h3 id="自适应图片-image-set"><a href="#自适应图片-image-set" class="headerlink" title="自适应图片 image-set()"></a>自适应图片 <code>image-set()</code></h3><p>image-set()函数是一种让浏览器从给定集合中选择最合适的CSS图像的方法。</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">background-image: image-<span class="built_in">set</span>( <span class="string">&quot;cat.png&quot;</span> <span class="number">1</span>x,<span class="string">&quot;cat-2x.png&quot;</span> <span class="number">2</span>x,<span class="string">&quot;cat-print.png&quot;</span> <span class="number">600</span>dpi);</span><br></pre></td></tr></table></figure>

<p>在普通屏幕上会使用cat.png，在<strong>Retina</strong>屏幕上使用cat-2x.png，在更高分辨率的屏幕上使用cat-print.png。 关于响应式图片可以参考<a target="_blank" rel="noopener" href="https://juejin.cn/post/7027807945903570957" title="https://juejin.cn/post/7027807945903570957">响应式图片</a></p>
<h3 id="shadow-dom中的-slotted"><a href="#shadow-dom中的-slotted" class="headerlink" title="shadow dom中的::slotted()"></a>shadow dom中的<code>::slotted()</code></h3><p>这也是一个伪类，代表的是自定义元素传过来的slot：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"> &lt;<span class="selector-tag">span</span> slot=&quot;person-age&quot;&gt;Immortal&lt;/<span class="selector-tag">span</span>&gt;</span><br><span class="line"><span class="selector-pseudo">::slotted</span>(<span class="selector-tag">span</span>) &#123;<span class="attribute">font-weight</span>:bold; <span class="attribute">color</span>: gray; <span class="attribute">font-family</span>: sans-serif; &#125; </span><br></pre></td></tr></table></figure>

<p>外部传过来的<code>span</code>元素会被应用该样式。</p>
<p>完整demo：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">person-details</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">slot</span>=<span class="string">&quot;person-name&quot;</span>&gt;</span>Dr. Shazaam<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">slot</span>=<span class="string">&quot;person-age&quot;</span>&gt;</span>Immortal<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">slot</span>=<span class="string">&quot;person-occupation&quot;</span>&gt;</span>Superhero<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">person-details</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">template</span> <span class="attr">id</span>=<span class="string">&quot;person-template&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h2</span>&gt;</span>Personal ID Card<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">slot</span> <span class="attr">name</span>=<span class="string">&quot;person-name&quot;</span>&gt;</span>NAME MISSING<span class="tag">&lt;/<span class="name">slot</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">slot</span> <span class="attr">name</span>=<span class="string">&quot;person-age&quot;</span>&gt;</span>AGE MISSING<span class="tag">&lt;/<span class="name">slot</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">slot</span> <span class="attr">name</span>=<span class="string">&quot;person-occupation&quot;</span>&gt;</span>OCCUPATION MISSING<span class="tag">&lt;/<span class="name">slot</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    customElements.<span class="title function_">define</span>(<span class="string">&#x27;person-details&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">class</span> <span class="title class_">extends</span> <span class="title class_">HTMLElement</span> &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="title function_">constructor</span>(<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="variable language_">super</span>();</span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">let</span> template = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;person-template&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">let</span> templateContent = template.<span class="property">content</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">const</span> shadowRoot = <span class="variable language_">this</span>.<span class="title function_">attachShadow</span>(&#123; <span class="attr">mode</span>: <span class="string">&#x27;open&#x27;</span> &#125;);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">let</span> style = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&#x27;style&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">                style.<span class="property">textContent</span> = <span class="string">&#x27;div &#123; padding: 10px; border: 1px solid gray; width: 200px; margin: 10px; &#125;&#x27;</span> +</span></span><br><span class="line"><span class="language-javascript">                    <span class="string">&#x27;h2 &#123; margin: 0 0 10px; &#125;&#x27;</span> +</span></span><br><span class="line"><span class="language-javascript">                    <span class="string">&#x27;ul &#123; margin: 0; &#125;&#x27;</span> +</span></span><br><span class="line"><span class="language-javascript">                    <span class="string">&#x27;p &#123; margin: 10px 0; &#125;&#x27;</span> +</span></span><br><span class="line"><span class="language-javascript">                    <span class="string">&#x27;::slotted(*) &#123;font-weight:bold; color: gray; font-family: sans-serif; &#125; &#x27;</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">                shadowRoot.<span class="title function_">appendChild</span>(style);</span></span><br><span class="line"><span class="language-javascript">                shadowRoot.<span class="title function_">appendChild</span>(templateContent.<span class="title function_">cloneNode</span>(<span class="literal">true</span>));</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/cf06032c734549a09510f6424aaa5b81.png" alt="image.png"></p>
<h3 id="element"><a href="#element" class="headerlink" title="element"></a>element</h3><p>目前只有Firefox实现了。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;<span class="selector-tag">div</span> style=&quot;<span class="attribute">width</span>:<span class="number">400px</span>; <span class="attribute">height</span>:<span class="number">400px</span>; <span class="attribute">background</span>:<span class="built_in">-moz-element</span>(#myBackground1) no-repeat;&quot;&gt;</span><br><span class="line">  &lt;<span class="selector-tag">p</span>&gt;This box uses the element with the <span class="selector-id">#myBackground1</span> ID as its <span class="attribute">background</span>!&lt;/<span class="selector-tag">p</span>&gt;</span><br><span class="line">&lt;/<span class="selector-tag">div</span>&gt;</span><br><span class="line"></span><br><span class="line">&lt;<span class="selector-tag">div</span> style=&quot;<span class="attribute">overflow</span>:hidden; <span class="attribute">height</span>:<span class="number">0</span>;&quot;&gt;</span><br><span class="line">  &lt;<span class="selector-tag">div</span> id=&quot;myBackground1&quot; style=&quot;<span class="attribute">width</span>:<span class="number">1024px</span>; <span class="attribute">height</span>:<span class="number">1024px</span>; <span class="attribute">background-image</span>: <span class="built_in">linear-gradient</span>(to right, red, orange, yellow, white);&quot;&gt;</span><br><span class="line">  &lt;<span class="selector-tag">p</span> style=&quot;<span class="attribute">transform-origin</span>:<span class="number">0</span> <span class="number">0</span>; <span class="attribute">transform</span>: <span class="built_in">rotate</span>(<span class="number">45deg</span>); <span class="attribute">color</span>:white;&quot;&gt;This text is part of the <span class="attribute">background</span>. Cool, huh?&lt;/<span class="selector-tag">p</span>&gt;</span><br><span class="line">  &lt;/<span class="selector-tag">div</span>&gt;</span><br><span class="line">&lt;/<span class="selector-tag">div</span>&gt;</span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/2bb45eb7f59d40f381a2ad904fa739ea.png" alt="image.png"></p>
<h3 id="env"><a href="#env" class="headerlink" title="env"></a>env</h3><p>将用户代理定义的环境变量值插入你的 CSS 中。</p>
<p>最初由iOS浏览器提供，用于允许开发人员将其内容放置在视口的安全区域中，该规范中定义的<code>safe-area-inset-*</code> 值可用于确保内容即使在非矩形的视区中也可以完全显示。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">body</span> &#123; <span class="attribute">padding</span>: </span><br><span class="line">    <span class="built_in">env</span>(safe-area-inset-top) </span><br><span class="line">    <span class="built_in">env</span>(safe-area-inset-right) </span><br><span class="line">    <span class="built_in">env</span>(safe-area-inset-bottom)</span><br><span class="line">    <span class="built_in">env</span>(safe-area-inset-left); </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="counter-和-counters"><a href="#counter-和-counters" class="headerlink" title="counter 和 counters"></a>counter 和 counters</h3><p>counter可以获取代表计数器当前值的字符串，counters可以获取嵌套计数器的当前代表值。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">ol</span> &#123;</span><br><span class="line">  <span class="attribute">counter-reset</span>: listCounter;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-tag">li</span> &#123;</span><br><span class="line">  <span class="attribute">counter-increment</span>: listCounter;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-tag">li</span><span class="selector-pseudo">::after</span> &#123;</span><br><span class="line">  <span class="attribute">content</span>: <span class="string">&quot;[&quot;</span> <span class="built_in">counter</span>(listCounter) <span class="string">&quot;] == [&quot;</span></span><br><span class="line">               <span class="built_in">counter</span>(listCounter, upper-roman) <span class="string">&quot;]&quot;</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/6d8aa40eee8a404c894642e4c613d7ff.png" alt="image.png"></p>
<h2 id="未来"><a href="#未来" class="headerlink" title="未来"></a>未来</h2><p>css的函数还在发展中，下面的特性有些有部分浏览器已经实现了，有些还在w3c讨论中。</p>
<h3 id="cross-fade"><a href="#cross-fade" class="headerlink" title="cross-fade()"></a><code>cross-fade()</code></h3><p>可将多张图片以一定的透明度混合。这个函数新老语法已经不一致了。</p>
<p>已经实现的老版语法的demo如下：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.crossfade</span> &#123;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">300px</span>;</span><br><span class="line">    <span class="attribute">height</span>: <span class="number">300px</span>;</span><br><span class="line">    <span class="attribute">background-image</span>: <span class="built_in">-webkit-cross-fade</span>(</span><br><span class="line">        <span class="built_in">url</span>(<span class="string">&#x27;br.png&#x27;</span>),</span><br><span class="line">        <span class="built_in">url</span>(<span class="string">&#x27;tr.png&#x27;</span>),</span><br><span class="line">        <span class="number">75%</span>);</span><br><span class="line">    <span class="attribute">background-image</span>: <span class="built_in">cross-fade</span>(</span><br><span class="line">        <span class="built_in">url</span>(<span class="string">&#x27;br.png&#x27;</span>),</span><br><span class="line">        <span class="built_in">url</span>(<span class="string">&#x27;tr.png&#x27;</span>),</span><br><span class="line">        <span class="number">75%</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="./../imgs/62e213d1a84048648ebc55b40cef1913.png" alt="image.png"></p>
<h3 id="dir"><a href="#dir" class="headerlink" title="dir()"></a><code>dir()</code></h3><p>设置文字书写方向，只有Firefox实现了。</p>
<h3 id="has"><a href="#has" class="headerlink" title="has()"></a><code>has()</code></h3><p>尚无浏览器实现</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 选择任何直接包含 &lt;img&gt; 子元素的 &lt;a&gt;  */</span></span><br><span class="line"><span class="comment">/* 注意，目前还没有任何浏览器支持此方法 */</span></span><br><span class="line"><span class="comment">/* 此伪类也未计划投入样式表中使用 */</span></span><br><span class="line"><span class="selector-tag">var</span> test = document<span class="selector-class">.querySelector</span>(&#x27;<span class="selector-tag">a</span><span class="selector-pseudo">:has</span>(&gt; <span class="selector-tag">img</span>)&#x27;);</span><br></pre></td></tr></table></figure>

<h3 id="数学函数"><a href="#数学函数" class="headerlink" title="数学函数"></a>数学函数</h3><ul>
<li>正弦： <code>sin()</code></li>
<li>余弦： <code>cos()</code></li>
<li>切线： <code>tan()</code></li>
<li>反余弦： <code>acos()</code></li>
<li>反正弦： <code>asin()</code></li>
<li>反正切： <code>atan()</code></li>
<li>反正切： <code>atan2()</code></li>
<li>平方根： <code>sqrt()</code></li>
<li>参数平方和的平方根： <code>hypot()</code></li>
<li>幂函数： <code>pow()</code></li>
</ul>
<h3 id="host-和-host-context"><a href="#host-和-host-context" class="headerlink" title=":host() 和 :host-context()"></a><code>:host()</code> 和 <code>:host-context()</code></h3><p>在shadow dom中使用</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment">    选择阴影根元素，仅当它与选择器参数匹配</span></span><br><span class="line"><span class="comment">    如：&lt;context-span class=&quot;footer&quot;&gt;Chris Mills&lt;/context-span&gt; </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"> <span class="selector-pseudo">:host</span>(<span class="selector-class">.footer</span>) &#123;</span><br><span class="line">   <span class="attribute">font-weight</span>: bold;</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">    选择了一个 shadow root host, 当且仅当这个</span></span><br><span class="line"><span class="comment"> shadow root host 是括号中选择器参数(h1)的后代 </span></span><br><span class="line"><span class="comment"> 如： &lt;h1&gt;Host selectors &lt;a href=&quot;#&quot;&gt;&lt;context-span&gt;example&lt;/context-span&gt;&lt;/a&gt;&lt;/h1&gt;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="selector-pseudo">:host</span>-context(<span class="selector-tag">h1</span>) &#123;</span><br><span class="line">  <span class="attribute">font-weight</span>: bold;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="nth-col-和-nth-last-col"><a href="#nth-col-和-nth-last-col" class="headerlink" title=":nth-col() 和 :nth-last-col()"></a><code>:nth-col()</code> 和 <code>:nth-last-col()</code></h3><p>在网格布局中使用，定义某一&#x2F;些列</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:nth-col</span>(odd) &#123;</span><br><span class="line">  <span class="attribute">background-color</span>: pink;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="symbols"><a href="#symbols" class="headerlink" title="symbols()"></a><code>symbols()</code></h3><p>定义计数器样式,只有Firefox实现了</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">ol</span> &#123;</span><br><span class="line">  <span class="attribute">list-style</span>: <span class="built_in">symbols</span>(cyclic <span class="string">&quot;*&quot;</span> <span class="string">&quot;†&quot;</span> <span class="string">&quot;‡&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
        
      </div>

         
    </div>
    
     
  </div>
  
    
<nav id="article-nav">
  <a class="article-nav-btn left "
    
      href="/hexo-blog/2021/11/28/React%20library%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8%E2%80%94%E2%80%94Mobx/"
      title="React library快速入门——Mobx"
     >
    <i class="fa-solid fa-angle-left"></i>
    <p class="title-text">
      
        React library快速入门——Mobx
        
    </p>
  </a>
  <a class="article-nav-btn right "
    
      href="/hexo-blog/2021/11/26/CSS%E5%87%BD%E6%95%B0%E5%A4%A7%E5%85%A8%EF%BC%88%E4%B8%89%EF%BC%89%EF%BC%9A%E9%A2%9C%E8%89%B2%E3%80%81%E6%B8%90%E5%8F%98%E5%92%8C%E6%BB%A4%E9%95%9C/"
      title="CSS函数大全（三）：颜色、渐变和滤镜"
     >

    <p class="title-text">
      
        CSS函数大全（三）：颜色、渐变和滤镜
        
    </p>
    <i class="fa-solid fa-angle-right"></i>
  </a>
</nav>


  
</article>





    </div>
    <div id="footer-wrapper">
      <footer id="footer">
  
  <div id="footer-info" class="inner">
    
    &copy; 2024 Zachary<br>
    <!-- Powered by <a href="https://hexo.io/" target="_blank">Hexo</a> & Theme <a target="_blank" rel="noopener" href="https://github.com/saicaca/hexo-theme-vivia">Vivia</a> -->
      <a target="_blank" rel="noopener" href="https://beian.miit.gov.cn">苏ICP备20030005号-2</a>
  </div>
</footer>

    </div>
    <div class="back-to-top-wrapper">
    <button id="back-to-top-btn" class="back-to-top-btn hide" onclick="topFunction()">
        <i class="fa-solid fa-angle-up"></i>
    </button>
</div>

<script>
    function topFunction() {
        window.scroll({ top: 0, behavior: 'smooth' });
    }
    let btn = document.getElementById('back-to-top-btn');
    function scrollFunction() {
        if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) {
            btn.classList.remove('hide')
        } else {
            btn.classList.add('hide')
        }
    }
    window.onscroll = function() {
        scrollFunction();
    }
</script>

  </div>
  <script src="/hexo-blog/js/light-dark-switch.js"></script>
</body>
</html>
